package com.shu.lock;

import java.util.concurrent.locks.LockSupport;

/**
 * @author ssm
 * @version V1.0
 * @description:
 * @date 2020/8/27 11:34
 */

public class Park_unpark {

    static Thread t1 = null, t2 = null;

    public static void main(String[] args) {


        char[] a1 = "123456".toCharArray();
        char[] b1 = "abcdef".toCharArray();


        t1 = new Thread(() -> {
            for (final char c : a1) {
                System.out.println(c);
                LockSupport.unpark(t2);
                LockSupport.park();
            }

        }, "t1");


        t2 = new Thread(() -> {
            for (final char c : b1) {
                LockSupport.park();
                System.out.println(c);
                LockSupport.unpark(t1);
            }

        }, "t2");

        t1.start();
        t2.start();
    }
}
